/**
 * 公共库
 */

const dayjs = require('dayjs');

/**
 * 年龄
 * @param {*} idNo 身份证号号
 */
const getAge = (idNo) => {
    const birth = idNo.slice(6, 14);
    let birthDay = birth.split('');
    birthDay.splice(4, 0, '-');
    birthDay.splice(7, 0, '-');
    birthDay = birthDay.join('');
    if (new Date(birthDay).toString() === 'Invalid Date') {
        return -1;
    }
    const date = dayjs(new Date());
    const age = date.diff(birthDay, 'year');
    return age;
}

/**
 * 是否为空对象
 * @param {*} obj 要校验的对象
 * @returns 
 */
const isEmptyObject = (obj) => !obj || Object.keys(obj).length === 0;

module.exports = {
    getAge,
    isEmptyObject
}